# coding=utf-8
# @Time   : 2023/11/26
# @Author : wangjl
# @Email  : 1975039138@qq.com
import logging
import os
import uuid


def get_logger_path(log_dir="./logs", current_file=None):
    if not current_file:
        current_file = os.path.basename(__file__)[:-len(".py")]
    unique_id = str(uuid.uuid4())
    file_path = os.path.abspath(os.path.join(log_dir, f"{current_file}-{unique_id}.log"))
    return file_path


def get_logger(file_path, level: int = logging.INFO):
    default_format = "$(asctime)s - %(levelname)s - %(message)s"
    logging.basicConfig(level=level, format=default_format)
    file_handler = logging.FileHandler(file_path)
    file_handler.setLevel(level)
    formatter = logging.Formatter(default_format)
    file_handler.setFormatter(formatter)
    logger = logging.getLogger()
    logger.addHandler(file_handler)
    return logger
